$.fn.vldMapPage = function(options) {
	console.log('starting to parse RDFa');
	store = $().rdf();
	console.log('parsed RDFa');
	
	console.log('mapping');
	$(this).vldMapStore(store, options);
	console.log('mapped');
}


$.fn.vldMapData = function(data, options) {
	store = jQuery.rdf();
	store.load(data);
	$(this).vldMapStore(store, options);
}

$.fn.vldMapStore = function(store, options) {
	var mapDiv = $(this);

	var map = new google.maps.Map(
		document.getElementById( mapDiv.attr('id') ),
		options
	);

	store.where (
		'?thing <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat'
	).where (
		'?thing <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long'
	).optional (
		'?thing <http://www.w3.org/2000/01/rdf-schema#label> ?label'
	).optional (
		'?thing <http://example.com/schema/mapIcon> ?mapIcon'
	).each (
		function() {
			var position = new google.maps.LatLng(this.lat.value, this.long.value);
			var title = this.label ? this.label.value : 'Unnamed Item';
			var image = this.icon ? this.icon.value.toString() : null;
			var marker = new google.maps.Marker({
				position: position,
				title: title,
				map: map,
				icon: image
			});
		}
	);
}

$.fn.vldMapUrl = function(url, options) {
	var mapDiv = $(this);
	var map = new google.maps.Map(
		document.getElementById( mapDiv.attr('id') ),
		options
	);
	
	$.getJSON(url,
		function(jsonData) {
			store = jQuery.rdf();
			store.load(jsonData);
			store.where (
				'?thing <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat'
			).where (
				'?thing <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?long'
			).optional (
				'?thing <http://www.w3.org/2000/01/rdf-schema#label> ?label'
			).optional (
				'?thing <http://example.com/schema/mapIcon> ?icon'
			).each (
				function() {
					var position = new google.maps.LatLng(this.lat.value, this.long.value);
					var title = this.label ? this.label.value : 'Unnamed Item';
					var image = this.icon ? this.icon.value.toString() : null;
					var marker = new google.maps.Marker({
						position: position,
						title: title,
						map: map,
						icon: image
					});
				}
			);
		}
	);
}